﻿/* 
 *  <copyright file="ToggleVisibilityCmp.cs" company="Wesley Jowitt">
 *  
 *  SobrietyEngine: Copyright (c) 2011 Wesley Jowitt
 *  
 *  This software is distributed under a software license.
 *   * As of the creation time of this file, the license in use is the Microsoft Permissive License (Ms-PL) 
 *    * The license can be viewed at:
 *     * License.Txt in the root folder of this project
 *      * http://sobrietyengine.codeplex.com/license
 *       * http://www.microsoft.com/opensource/licenses.mspx
 *       
 *  </copyright>
 *   */

using System;
using System.Collections.Generic;

using SobrietyEngine.Guids;
using SobrietyEngine.Actor;

namespace SobrietyEngine.Components.Trigger.Response
{
    public class ToggleVisibilityCmp:TriggerResponseBase
    {
        IGraphicVisibility graphic;

        public ToggleVisibilityCmp()
            : base()
        {
        }

        public ToggleVisibilityCmp(String[] triggerActor)
            : base(triggerActor)
        {
        }

        override public Boolean InitComponent()
        {
            base.InitComponent();

            graphic = Actor.Get<IGraphicVisibility>();
            if (graphic == null)
            {
                Logging.Logger.Error(this, "Couldnt find IGraphicVisibility providing component on parent actor");                
            }

            return true;
        }

        public override void Trigger(ITrigger trigger, CGuid byWho)
        {
            IActor trigAct = ((IComponent)trigger).Actor;
            ITrigger trig = trigAct.Get<ITrigger>();
            graphic.Visible = trig.TriggerValue;
        }

        public  override void Trigger(CGuid byWho)
        {
            graphic.Visible = !graphic.Visible;
        }
    }
}
